package com.cloud.spring.demo.feign.fallback;

import com.cloud.spring.demo.entity.User;
import com.cloud.spring.demo.feign.EurekaClient2Feign;
import feign.hystrix.FallbackFactory;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Log4j2
@Component
public class EurekaClient2HystrixFallbackFactory implements FallbackFactory<EurekaClient2Feign> {
    @Override
    public EurekaClient2Feign create(Throwable cause) {
        return new EurekaClient2Feign() {
            @Override
            public User getUser(int id) {
                log.warn("cause.getMessage: " + cause);
                return new User();
            }

            @Override
            public List<User> getUserList(User user) {
                log.warn("cause.getMessage: " + cause);
                return new ArrayList<>();
            }

            @Override
            public List<User> saveUserList(List<User> user) {
                log.warn("cause.getMessage: " + cause);
                return null;
            }
        };
    }
}
